package com.rustic.server.dto;

import cn.hutool.core.bean.BeanUtil;
import cn.xy.commons.enums.DataStatus;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.rustic.server.po.Food;
import com.rustic.server.dto.base.FoodBaseDTO;
import org.hibernate.validator.constraints.Length;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 表[food]对应AddDTO类
 *
 * @author auto
 */

@Data
@EqualsAndHashCode(callSuper = true)
public class FoodAddDTO extends FoodBaseDTO {
    /**
     * 关联乡村id
     */
    @NotNull(message = "关联乡村不能为空")
    @Min(value = 1, message = "关联乡村不能为空")
    @ApiModelProperty(value = "关联乡村id", dataType = "int")
    private int rusticId;

    /**
     * 美食名称
     */
    @NotEmpty(message = "美食名称不能为空")
    @Length(min = 0, max = 100, message = "美食名称长度为0-100个字符")
    @ApiModelProperty(value = "美食名称", dataType = "String")
    private String name;

    /**
     * 介绍
     */
    @NotEmpty(message = "介绍不能为空")
    @ApiModelProperty(value = "介绍", dataType = "String")
    private String introduce;

    /**
     * 封面
     */
    @NotEmpty(message = "封面不能为空")
    @Length(min = 0, max = 500, message = "封面长度为0-500个字符")
    @ApiModelProperty(value = "封面", dataType = "String")
    private String cover;

    /**
     * 图片(轮播图)
     */
    @Length(min = 0, max = 500, message = "图片(轮播图)长度为0-500个字符")
    @ApiModelProperty(value = "图片(轮播图)", dataType = "String")
    private String images;

    /**
     * 分类id
     */
    @NotNull(message = "分类不能为空")
    @Min(value = 1, message = "分类不能为空")
    @ApiModelProperty(value = "分类id", dataType = "int")
    private int categoryId;

    /**
     * 排序
     */
    @ApiModelProperty(value = "排序", dataType = "int")
    private int sort;

    @Valid
    @ApiModelProperty(value = "推荐餐厅", dataType = "List")
    private List<RestaurantAddDTO> restaurantList;


    public Food toFood() {
        Food food = new Food();
        BeanUtil.copyProperties(this, food);
        food.setDataStatus(DataStatus.NORMAL.getValue());
        return food;
    }
}
